//
//  GoodManagerMainCell.m
//  ReceiptDelivery
//
//  Created by 吕晶 on 2020/9/21.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "GoodManagerMainCell.h"

@interface GoodManagerMainCell ()

@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UILabel *nameLab;
@property (nonatomic, strong) UILabel *codeLab;
@property (nonatomic, strong) UILabel *bianMaTitleLab;
@property (nonatomic, strong) UILabel *bianMaLab;
@property (nonatomic, strong) UILabel *guiGeTitleLab;
@property (nonatomic, strong) UILabel *guiGeLab;
@property (nonatomic, strong) UIButton *deleteBtn;

@end

@implementation GoodManagerMainCell

+ (instancetype)GoodManagerMainCellWithTableView:(UITableView *)tableView {
    static NSString *cellID = @"GoodManagerMainCell";
    GoodManagerMainCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[GoodManagerMainCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = Color_backgroundColor;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.bgView = [[UIView alloc] initWithFrame:CGRectMake(15, 10, ScreenW - 30, 109)];
        self.bgView.backgroundColor = HexColor(0xffffff);
        self.bgView.layer.masksToBounds = YES;
        self.bgView.layer.cornerRadius = 6;
        [self.contentView addSubview:self.bgView];
        
        self.nameLab = [UILabel new];
        self.nameLab.textColor = HexColor(0x2B2C44);
        self.nameLab.font = BoldFontOfSize(18);
        [self.bgView addSubview:self.nameLab];
        
        self.codeLab = [UILabel new];
        self.codeLab.textColor = HexColor(0x9C9DB3);
        self.codeLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.codeLab];
        
        self.bianMaTitleLab = [UILabel new];
        self.bianMaTitleLab.textColor = HexColor(0x9C9DB3);
        self.bianMaTitleLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.bianMaTitleLab];
        
        self.bianMaLab = [UILabel new];
        self.bianMaLab.textColor = HexColor(0x2B2C44);
        self.bianMaLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.bianMaLab];
        
        self.guiGeTitleLab = [UILabel new];
        self.guiGeTitleLab.textColor = HexColor(0x9C9DB3);
        self.guiGeTitleLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.guiGeTitleLab];
        
        self.guiGeLab = [UILabel new];
        self.guiGeLab.textColor = HexColor(0x2B2C44);
        self.guiGeLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.guiGeLab];
        
        self.deleteBtn = [UIButton new];
        self.deleteBtn.backgroundColor = HexColorA(0xF35959, 0.1);
        self.deleteBtn.layer.masksToBounds = YES;
        [self.deleteBtn setTitle:@"删除" forState:0];
        [self.deleteBtn setTitleColor:HexColor(0xF35959) forState:0];
        self.deleteBtn.titleLabel.font = BoldFontOfSize(14);
        [self.deleteBtn addTarget:self action:@selector(deleteClick) forControlEvents:UIControlEventTouchUpInside];
        [self.bgView addSubview:self.deleteBtn];
        
        self.height = self.bgView.nim_bottom;
    }
    return self;
}

- (void)deleteClick {
    if (self.deleteBlock) {
        self.deleteBlock();
    }
}

-(void)setModel:(GoodManagerMainModel *)model {
    _model = model;
    [self configUI];
}

- (void)configUI {
    self.nameLab.text = self.model.name;
    [self.nameLab sizeToFit];
    self.nameLab.nim_left = 10;
    self.nameLab.nim_top = 15;
    
    self.codeLab.text = self.model.pro_num;
    [self.codeLab sizeToFit];
    self.codeLab.nim_left = self.nameLab.nim_right + 5;
    self.codeLab.nim_bottom = self.nameLab.nim_bottom;
    
    self.bianMaTitleLab.text = @"原始编码：";
    [self.bianMaTitleLab sizeToFit];
    self.bianMaTitleLab.nim_left = 10;
    self.bianMaTitleLab.nim_top = self.bgView.nim_height - 15 - self.bianMaTitleLab.nim_height * 2 - 5;
    
    self.bianMaLab.text = self.model.num;
    [self.bianMaLab sizeToFit];
    self.bianMaLab.nim_left = self.bianMaTitleLab.nim_right;
    self.bianMaLab.nim_top = self.bianMaTitleLab.nim_top;
    
    self.guiGeTitleLab.text = @"货物规格：";
    [self.guiGeTitleLab sizeToFit];
    self.guiGeTitleLab.nim_left = 10;
    self.guiGeTitleLab.nim_top = self.bianMaTitleLab.nim_bottom + 5;
    
    self.guiGeLab.text = self.model.specs;
    [self.guiGeLab sizeToFit];
    self.guiGeLab.nim_left = self.guiGeTitleLab.nim_right;
    self.guiGeLab.nim_top = self.guiGeTitleLab.nim_top;
    
    self.deleteBtn.frame = CGRectMake(self.bgView.nim_width - 20 - 64, (self.bgView.nim_height - 30) * 0.5, 64, 30);
    self.deleteBtn.layer.cornerRadius = 15;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
